<template>
	<view>
		<view>
			<view class="addrs-item" v-for="(item,index) in addrs" :key = "index" style="display: flex; justify-content: space-between;">
				<view>
					<text>{{item.addrContact}}</text>
					<text style="font-size: 24rpx; color: gray;margin-left: 10rpx;">{{item.addrPhone}}</text>
					<view>
						<text style="font-size: 24rpx; color: gray;">{{item.addrContent}}</text>
					</view>
				</view>
				<view style="margin-right: 40rpx; margin-top: 20rpx;" @click="toAdd(index)">
					<uni-icons type="gear" size="20"></uni-icons>
				</view>
				
			</view>
			
		</view>
		<button size="default" type="default" 
			style="color:#ffffff;backgroundColor:#1AAD19;borderColor:#1AAD19;position: fixed; bottom: 15rpx; width: 90%; margin-left:40rpx;" 
			hover-class="is-hover"   @click="toAdd(-1)">添加新地址
		</button>
		
	</view>

</template>

<script>
	export default {
		data() {
			return {
				userId:1,
				addrs:[
					{
						userId:1,
						addrId:1,
						addrContact:'周佳成',
						userSex:0,
						addrPhone:'12345678910',
						addrContent:"南昌大学软件学院"
					},
					{
						userId:1,
						addrId:2,
						addrContact:'周佳成',
						userSex:0,
						addrPhone:'12345678910',
						addrContent:"南昌大学软件学院"
					},
					
				]
			}
		},
		onLoad(){
			//加载数据
			this.request({
				url:"/base-position/list",
				method:'GET',
				data:{
				     
				},
				
			}).then(res=>{
				if(res.code==='1'){
					console.log("成功")
					this.addrs = res.data
				}
				else{
					console.log("失败")
				}
			}).catch(()=>{
				console.log("系统错误")
			
			})
		},
		
		methods: {
			toAdd(index){
				var addrData = {
					userId:this.userId,
					addrId:null,
					addrContact:null,
					userSex:null,
					addrPhone:null,
					addrContent:null
				}
				if(index!=-1){
					addrData = this.addrs[index]
				}
				addrData = JSON.stringify(addrData)
				uni.navigateTo({
					
					url:'/pages/add_position/add_position?addrData='+addrData
				})
			}
		}
	}
</script>

<style>
.is-hover {
	color: rgba(255, 255, 255, 0.6);
	background-color: #179b16;
	border-color: #179b16;
  }
  .addrs-item {
	  border-bottom: #f1f1f1f1 solid 2rpx;
	  width: 100%;
	  padding-bottom: 24rpx;
	  margin-top: 24rpx;
	  margin-bottom: 24rpx;
	  margin-left: 24rpx;
  }
</style>
